<template>
  <div>
    
    <h1 style="color: black">请上传上传Exel文件</h1>
    <input multiple="multiple" type="file" id="uploadFile" />
    

    <button @click="upload">上传</button>
    <!-- <el-button type="primary" @click="upload"
      >上传<i class="el-icon-upload el-icon--right"></i
    ></el-button> -->
    
  </div>
</template>
  <script>
import $ from 'jquery'

export default {
  methods: {
    upload: function () {
      var formData = new FormData() // 创建一个formData对象实例
      var excelFile = $('#uploadFile').get(0).files[0]
      formData.append('excelFile', excelFile)
      $.ajax({
        url: 'http://localhost:8088/upload',
        data: formData,
        type: 'post',
        contentType: false, // 必须false才会自动加上正确的Content-Type
        processData: false, // 必须false才会避开jQuery对 formdata 的默认处理,XMLHttpRequest会对 formdata 进行正确的处理
        success: function (resp) {
          console.log(resp)
          alert('上传成功!')
          location.reload(0)
        },
      })
    },
  },
}
</script>
  